package com.lanou.student.page;

import java.awt.print.Printable;
import java.util.Date;
import java.util.Scanner;

import com.lanou.student.bean.Student;
import com.lanou.student.bean.User;
import com.lanou.student.controller.StudentController;
import com.lanou.student.util.PasswordUtil;

/**
 * /打印所有用户信息 //添加 //更新 //删除 通过用户名删除 //通过用户去查 //注销
 * 
 * @author Lenovo
 *
 */
public class Index {
	private Scanner sc = new Scanner(System.in);
	private StudentController studentController;
	private int id = 2;
	public Index(StudentController studentController) {
		this.studentController = studentController;
	}

	public void index() {
		boolean flag = true;
		while (flag) {
			System.out.println("=========欢迎学生信息管理系统首页=========");
			// 打印出所有的学生信息
			print();
			System.out.println("\t(1)、添加\t(2)、更新");
			System.out.println("\t(3)、删除\t(4)、注销");
			System.out.println("\t\t请选择");
			switch (sc.nextInt()) {
			case 1:
				Student s = getStudent();
				if(studentController.add(s)) {
					System.out.println("添加成功");
				}else {
					System.out.println("添加失败");
				}
				break;
			case 2:
				
				// 更新
				break;
			case 3:
				System.out.println("请输入你需要删除的id");
				if(studentController.delete(sc.nextInt())) {
					System.out.println("删除成功");
				}else {
					System.out.println("删除失败");
				}
				break;
			case 4:
				flag = false;
				break;

			default:
				System.out.println("你选择有误，请重新选择");
				break;
			}
		}

	}

	private Student getStudent() {
		System.out.println("请输入学生姓名");
		String stuName = sc.next();
		System.out.println("请输入学生年龄");
		int stuAge = sc.nextInt();
		System.out.println( "请输入学生数学成绩");
		double math = sc.nextDouble();
		System.out.println("请输入英语成绩");
		double eng = sc.nextDouble();
		System.out.println("请输入计算机成绩");
		double computer = sc.nextDouble();
		
		return new Student(id++,stuName,stuAge,math,eng,computer);
	}

	private void print() {
		Student[] students = studentController.getStudents();
		System.out.println("id\t姓名\t年龄\t数学\t英语\t计算机");
	
		
		for (Student student : students) {
			System.out.println(student);
		}
		
	}

}
